/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.totoland.web.controller.report;

import com.totoland.db.report.entity.ViewSummary;
import com.totoland.web.controller.BaseController;
import com.totoland.web.service.ReportViewSummaryService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
//import org.primefaces.model.chart.Axis;
//import org.primefaces.model.chart.AxisType;
//import org.primefaces.model.chart.BarChartModel;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;
//import org.primefaces.model.chart.HorizontalBarChartModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author totoland
 */
@ManagedBean
@ViewScoped
public class ReportSummaryController extends BaseController {

    private static final long serialVersionUID = 1007114614954046889L;

    private static final Logger LOGGER = LoggerFactory.getLogger(ReportSummaryController.class);
    
    private CartesianChartModel barModel;
    
    private List<ViewSummary>listViewSummary;
 
    @ManagedProperty("#{reportViewSummaryService}")
    private ReportViewSummaryService reportViewSummaryService;
    
    @PostConstruct
    public void init() {
        createBarModels();
    }
 
    public CartesianChartModel getBarModel() {
        return barModel;
    }
 
    private CartesianChartModel initBarModel() {
        CartesianChartModel model = new CartesianChartModel();
 
        ViewSummary viewSummay = reportViewSummaryService.getViewSummay();
        
        String toDay = dateTH(new Date(), "dd/MM/yyyy");
        
        ChartSeries viewSummay1 = new ChartSeries();
        viewSummay1.setLabel("นศ.ยังไม่ได้ทำบัตร");
        viewSummay1.set(toDay, viewSummay.getNotCupture());
        
        ChartSeries viewSummay2 = new ChartSeries();
        viewSummay2.setLabel("นศ.ทำบัตรแล้ว");
        viewSummay2.set(toDay, viewSummay.getCuptured());
        
        ChartSeries viewSummay3 = new ChartSeries();
        viewSummay3.setLabel("นศ.ทั้งหมด");
        viewSummay3.set(toDay, viewSummay.getAllCupture());
        
        model.addSeries(viewSummay1);
        model.addSeries(viewSummay2);
        model.addSeries(viewSummay3);
        
        
        listViewSummary = new ArrayList<>();
        listViewSummary.add(viewSummay);
        
        return model;
    }
     
    private void createBarModels() {
        createBarModel();
    }
     
    private void createBarModel() {
        barModel = initBarModel();
         
//        barModel.setTitle("สรุปจำนวน นศ.เข้ารับการถ่ายบัตร");
//        barModel.setLegendPosition("ne");
//         
//        Axis xAxis = barModel.getAxis(AxisType.Y);
//        xAxis.setLabel("จำนวนคน");
//         
//        Axis yAxis = barModel.getAxis(AxisType.X);
//        yAxis.setLabel("วันที่");
//        yAxis.setMin(0);
//        yAxis.setMax(4600);
    }
    
    @Override
    public void resetForm() {
        
    }

    /**
     * @return the reportViewSummaryService
     */
    public ReportViewSummaryService getReportViewSummaryService() {
        return reportViewSummaryService;
    }

    /**
     * @param reportViewSummaryService the reportViewSummaryService to set
     */
    public void setReportViewSummaryService(ReportViewSummaryService reportViewSummaryService) {
        this.reportViewSummaryService = reportViewSummaryService;
    }

    /**
     * @return the listViewSummary
     */
    public List<ViewSummary> getListViewSummary() {
        return listViewSummary;
    }

    /**
     * @param listViewSummary the listViewSummary to set
     */
    public void setListViewSummary(List<ViewSummary> listViewSummary) {
        this.listViewSummary = listViewSummary;
    }
}
